
package com.cskaoyan.controller.admin.goodscontroller;

import com.cskaoyan.bean.goods.Goods;
import com.cskaoyan.bean.goods.GoodsComment;
import com.cskaoyan.bo.goodsvo.GoodsCreateBo;
import com.cskaoyan.bo.goodsvo.GoodsUpdateBo;
import com.cskaoyan.service.goods.GoodsService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.goodsvo.Category_CategoryList_Vo;
import com.cskaoyan.vo.goodsvo.GoodsComment_TotalVo;
import com.cskaoyan.vo.goodsvo.GoodsDetail_TotalVo;
import com.cskaoyan.vo.goodsvo.GoodsList_TotalVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GoodsController {

    @Autowired
    GoodsService goodsService;
    @RequiresPermissions("admin:goods:list")
    @RequestMapping("admin/goods/list")
    public BaseRespVo list(Integer page, Integer limit, String sort, String order, String goodsSn, String name){

        GoodsList_TotalVo goodsListVo = goodsService.query(page,limit,sort,order,goodsSn,name);
        return BaseRespVo.ok(goodsListVo);
    }
    @RequiresPermissions("admin:goods:read")
    @RequestMapping("admin/goods/detail")
    public BaseRespVo detail(Integer id){
        GoodsDetail_TotalVo goodsDetailVo = goodsService.detail(id);
        return BaseRespVo.ok(goodsDetailVo);
    }
    @RequiresPermissions("admin:goods:list")
    @RequestMapping("admin/goods/catAndBrand")
    public BaseRespVo catAndBrand(){

        Category_CategoryList_Vo vo = goodsService.catAndBrand();

        return BaseRespVo.ok(vo);
    }
    @RequiresPermissions("admin:goods:update")
    @RequestMapping("admin/goods/update")
    public BaseRespVo update(@RequestBody GoodsUpdateBo goodsUpdateBo){
        goodsService.update(goodsUpdateBo);
        return BaseRespVo.ok();
    }
    @RequiresPermissions("admin:goods:create")
    @RequestMapping("admin/goods/create")
    public BaseRespVo create(@RequestBody GoodsCreateBo goodsCreateBo){

        Integer flag = goodsService.create(goodsCreateBo);
        if(flag == 0){
            return BaseRespVo.fail611("商品名已经存在");
        }
        return BaseRespVo.ok();
    }

    @RequiresPermissions("admin:goods:delete")
    @RequestMapping("admin/goods/delete")
    public BaseRespVo delete(@RequestBody Goods goods){
        goodsService.delete(goods);
        return BaseRespVo.ok();
    }
    @RequiresPermissions("admin:comment:list")
    @RequestMapping("admin/comment/list")
    public BaseRespVo create(Integer page, Integer limit, String sort, String order, Integer userId, Integer valueId){
        GoodsComment_TotalVo goodsComment_totalVo = goodsService.queryComment(page,limit,sort,order,userId,valueId);
        return BaseRespVo.ok(goodsComment_totalVo);
    }
    @RequiresPermissions("admin:comment:delete")
    @RequestMapping("admin/comment/delete")
    public BaseRespVo deleteComment(@RequestBody GoodsComment comment){
        goodsService.deleteComment(comment);
        return BaseRespVo.ok();
    }
}

